package com.lc1993929.mr.rating.efficienttopn;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * Created by LiuChang on 2017/11/14/014.
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RateBean implements WritableComparable<RateBean> {
    private String movie;
    private String rate;
    private String timeStamp;
    private String uid;

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(this.movie);
        dataOutput.writeUTF(this.rate);
        dataOutput.writeUTF(this.timeStamp);
        dataOutput.writeUTF(this.uid);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.movie = dataInput.readUTF();
        this.rate = dataInput.readUTF();
        this.timeStamp = dataInput.readUTF();
        this.uid = dataInput.readUTF();
    }

    @Override
    public int compareTo(RateBean o) {
        if (this.uid.equals(o.getUid())) {
            return -this.rate.compareTo(o.getRate());
        } else {
            return this.uid.compareTo(o.getUid());
        }
    }
}
